#include<iostream>
#include<vector>
#include<queue>
using namespace std;


int main()
{
    int n(0);
    cin >> n;
    priority_queue<int, vector<int>,greater<int> > q;
    for(int i = 0; i < n; i++) 
    {
        int tmp1;
        cin >> tmp1;
        q.push(tmp1);
    }
    long long sum = 0;
    while(q.size() > 1)
    {
        int a1 = q.top();
        q.pop();
        int a2 = q.top();
        q.pop();
        int s = a1 + a2;
        q.push(s);
        sum += s;
    }
    cout << sum << endl;
}